home *** CD-ROM | disk | FTP | other *** search
/ Champak 64 / Volume 64 - JOGO DISK .iso / Games / the_best_every_day.swf / scripts / __Packages / sarbakan / visual / Camera.as next >
Text File  |  2008-04-10  |  4KB  |  166 lines

  1. class sarbakan.visual.Camera
  2. {
  3.    static var DEFAULT_SPEED = 10;
  4.    static var DEFAULT_EASING = mx.transitions.easing.Regular.easeOut;
  5.    function Camera(l_viewZoneW, l_viewZoneH, l_nStageW, l_nStageH)
  6.    {
  7.       mx.transitions.OnEnterFrameBeacon.init();
  8.       sarbakan.visual.Camera.oEnterFrameListener = new Object();
  9.       sarbakan.visual.Camera.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(this,this.update);
  10.       MovieClip.removeListener(sarbakan.visual.Camera.oEnterFrameListener);
  11.       MovieClip.addListener(sarbakan.visual.Camera.oEnterFrameListener);
  12.       this.nX = 0;
  13.       this.nY = 0;
  14.       this.nViewZoneW = l_viewZoneW;
  15.       this.nViewZoneH = l_viewZoneH;
  16.       this.nStageW = l_nStageW;
  17.       this.nStageH = l_nStageH;
  18.       this.setSpeed(sarbakan.visual.Camera.DEFAULT_SPEED);
  19.       this.setEasing(sarbakan.visual.Camera.DEFAULT_EASING);
  20.       this.bLockedOn = false;
  21.    }
  22.    function travelTo(l_nDestX, l_nDestY, l_fListener)
  23.    {
  24.       var _loc2_ = Math.round(sarbakan.utils.MoreMath.getDistance(this.nX * -1,this.nY * -1,l_nDestX,l_nDestY) / this.nSpeed);
  25.       if(!this.bTravelling)
  26.       {
  27.          this.oTweenX = new mx.transitions.Tween(this,"x",this.fEasing,this.nX * -1,l_nDestX,_loc2_,false);
  28.          this.oTweenY = new mx.transitions.Tween(this,"y",this.fEasing,this.nY * -1,l_nDestY,_loc2_,false);
  29.          this.oTweenX.onMotionFinished = mx.utils.Delegate.create(this,this.onTravelFinished);
  30.       }
  31.       else
  32.       {
  33.          this.oTweenX.continueTo(l_nDestX,_loc2_);
  34.          this.oTweenY.continueTo(l_nDestY,_loc2_);
  35.       }
  36.       this.nTravelDestX = l_nDestX;
  37.       this.nTravelDestY = l_nDestY;
  38.       if(l_fListener)
  39.       {
  40.          this.fEndListener = l_fListener;
  41.       }
  42.       this.bTravelling = true;
  43.    }
  44.    function moveTo(l_nDestX, l_nDestY)
  45.    {
  46.       this.__set__x(l_nDestX);
  47.       this.__set__y(l_nDestY);
  48.    }
  49.    function lockOn(l_fLockFunction, l_bInstant)
  50.    {
  51.       this.bLockedOn = true;
  52.       this.fLockedFunction = l_fLockFunction;
  53.       var _loc2_ = this.fLockedFunction();
  54.       if(_loc2_.x != this.nX || _loc2_.y != this.nY)
  55.       {
  56.          if(l_bInstant)
  57.          {
  58.             this.moveTo(_loc2_.x,_loc2_.y);
  59.          }
  60.          else
  61.          {
  62.             this.travelTo(_loc2_.x,_loc2_.y);
  63.          }
  64.       }
  65.    }
  66.    function unlock()
  67.    {
  68.       this.bLockedOn = false;
  69.       this.fLockedFunction = undefined;
  70.    }
  71.    function setSpeed(l_nSpeed)
  72.    {
  73.       if(l_nSpeed)
  74.       {
  75.          this.nSpeed = l_nSpeed;
  76.       }
  77.       else
  78.       {
  79.          this.setSpeed(sarbakan.visual.Camera.DEFAULT_SPEED);
  80.       }
  81.    }
  82.    function setEasing(l_fEasing)
  83.    {
  84.       if(l_fEasing)
  85.       {
  86.          this.fEasing = l_fEasing;
  87.       }
  88.       else
  89.       {
  90.          this.setEasing(sarbakan.visual.Camera.DEFAULT_EASING);
  91.       }
  92.    }
  93.    function set x(l_nX)
  94.    {
  95.       this.nX = l_nX;
  96.       if(this.nX < 0)
  97.       {
  98.          this.nX = 0;
  99.       }
  100.       if(this.nX > this.nViewZoneW - this.nStageW)
  101.       {
  102.          this.nX = Math.round(this.nViewZoneW - this.nStageW);
  103.       }
  104.       this.nX *= -1;
  105.    }
  106.    function set y(l_nY)
  107.    {
  108.       this.nY = l_nY;
  109.       if(this.nY < 0)
  110.       {
  111.          this.nY = 0;
  112.       }
  113.       if(this.nY > this.nViewZoneH - this.nStageH)
  114.       {
  115.          this.nY = Math.round(this.nViewZoneH - this.nStageH);
  116.       }
  117.       this.nY *= -1;
  118.    }
  119.    function getX()
  120.    {
  121.       return this.nX;
  122.    }
  123.    function getY()
  124.    {
  125.       return this.nY;
  126.    }
  127.    function destroy()
  128.    {
  129.       MovieClip.removeListener(sarbakan.visual.Camera.oEnterFrameListener);
  130.    }
  131.    function pause()
  132.    {
  133.       this.oTweenX.stop();
  134.       this.oTweenY.stop();
  135.    }
  136.    function unpause()
  137.    {
  138.       this.oTweenX.resume();
  139.       this.oTweenY.resume();
  140.    }
  141.    function update()
  142.    {
  143.       if(this.bLockedOn)
  144.       {
  145.          var _loc2_ = undefined;
  146.          if(!this.bTravelling && this.bLockedOn)
  147.          {
  148.             _loc2_ = this.fLockedFunction();
  149.             this.moveTo(_loc2_.x,_loc2_.y);
  150.          }
  151.          else if(_loc2_.x != this.nTravelDestX || _loc2_.y != this.nTravelDestY)
  152.          {
  153.          }
  154.       }
  155.    }
  156.    function onTravelFinished()
  157.    {
  158.       this.bTravelling = false;
  159.       if(this.fEndListener)
  160.       {
  161.          this.fEndListener();
  162.          this.fEndListener = undefined;
  163.       }
  164.    }
  165. }
  166.